package com.coocaa.internship.config;

import com.coocaa.internship.interceptor.UserLoginInterceptor;
import com.coocaa.internship.interceptor.UserRoleInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: web项目组件配置（静态资源处理）
 * @Author: zwh
 * @Date: 2019-07-29
 * @Time: 20:09
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private FileServerConfig fileServerConfig;

    @Autowired
    private PicServerConfig picServerConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/cv/**", "/logo/**")
                .addResourceLocations("file:" + fileServerConfig.getUploadPath() + "/", "file:" + picServerConfig.getUploadPath() + "/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserLoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/**/select", "/**/select*", "/sendValidateCode", "/LoginByValidateCode", "/cv/**", "/logo/**");
        registry.addInterceptor(new UserRoleInterceptor()).addPathPatterns("/positionInfo/**", "/company/**")
                .excludePathPatterns("/positionInfo/select*", "/company/select*");
    }
}
